﻿using NLog;
using NLog.LayoutRenderers;
using System.Diagnostics;
using System.Text;

namespace GetMan.Core.NLogRender
{
    [LayoutRenderer("process-memory-usage")]
    public class ProcessMemoryUsageLayoutRenderer : LayoutRenderer
    {
        private static readonly Process CurrentProcess = Process.GetCurrentProcess();

        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
        {
            // 获取当前进程的已使用内存（以 MB 为单位）
            var memoryUsage = CurrentProcess.WorkingSet64 / (1024 * 1024); // 将字节转换为 MB
            builder.Append($"{memoryUsage:0.0} MB");
        }
    }
}